package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.mapper.ServiceItemsMapper;
import com.jt.pojo.ServiceItems;
import com.jt.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ServiceItemsServiceImpl implements ServiceItemsService{
    @Autowired
    private ServiceItemsMapper serviceItemsMapper;
    @Override
    public PageResult getServiceitemsList(PageResult pageResult) {
        QueryWrapper<ServiceItems> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasLength(pageResult.getQuery()),"name",pageResult.getQuery());

        IPage<ServiceItems> page = new Page<>(pageResult.getPageNum(),pageResult.getPageSize());
        page   =  serviceItemsMapper.selectPage(page,queryWrapper);
        long total = page.getTotal();
        List<ServiceItems> rows = page.getRecords();
        return pageResult.setTotal(total).setRows(rows);
    }

    @Override
    @Transactional
    public void addServiceitems(ServiceItems serviceItems) {
        serviceItemsMapper.insert(serviceItems);
    }

    @Override
    @Transactional
    public void updateServiceitemsStatus(ServiceItems serviceItems) {
        serviceItemsMapper.updateById(serviceItems);
    }

    @Override
    public ServiceItems getServiceitems(Integer id) {
        return serviceItemsMapper.selectById(id);
    }

    @Override
    @Transactional
    public void deleteServiceitems(Integer id) {
        serviceItemsMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void updateServiceitems(ServiceItems serviceItems) {
        serviceItemsMapper.updateById(serviceItems);

    }


}
